<template>
  <div class="info" v-loading="loading">
    <div class="card_con mb15">
      <el-row class="mb15">
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">订单号：</div>
          <el-input v-model="orderId" placeholder="请输入订单号"></el-input>
        </el-col>
        <el-col :span="5" class="pr40">
          <div class="fz13 mb10">发货状态：</div>
          <el-select clearable v-model="deliverId" placeholder="请选择">
            <el-option
              v-for="item in deliverArr"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
          <!-- <el-input v-model="orderId" placeholder="请输入订单号"></el-input> -->
        </el-col>
        <el-col :span="9" class="pr40">
          <div class="fz13 mb10">时间</div>
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="time"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-col>
        <el-col :span="4">
          <div class="fz13 mb10">&nbsp;</div>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="card_con">
      <el-table
        border
        :data="tableData"
        :header-cell-style="{
          'text-align': 'center',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        highlight-current-row
      >
        <!-- <el-table-column type="selection" min-width="15%"> </el-table-column> -->
        <el-table-column prop="id" label="id" min-width="15%">
        </el-table-column>
        <el-table-column prop="oid" label="订单号" min-width="25%">
        </el-table-column>
        <el-table-column prop="price" label="订单金额" min-width="20%">
        </el-table-column>
        <el-table-column prop="shipping_price" label="运费" min-width="20%">
        </el-table-column>
        <!-- <el-table-column prop="shipping_way" label="配送方式" min-width="20%">
          <template slot-scope="scope">
            <div v-if="scope.row.shipping_way === 1" class="red">邮寄</div>
            <div v-if="scope.row.shipping_way === 2">到店</div>
          </template>
        </el-table-column> -->
        <el-table-column prop="total_amount" label="总金额" min-width="20%">
        </el-table-column>
        <el-table-column prop="pay_time" label="支付时间" min-width="25%">
        </el-table-column>
        <el-table-column prop="create_time" label="下单时间" min-width="25%">
        </el-table-column>
        <el-table-column prop="status_text" label="状态" min-width="20%">
          <template slot-scope="scope">
            <div v-if="scope.row.status_text === '待支付'" class="red">
              待支付
            </div>
            <div v-if="scope.row.status_text === '待发货'" class="orange">
              待发货
            </div>
            <div v-if="scope.row.status_text === '待收货'" class="orange">
              待收货
            </div>
            <div v-if="scope.row.status_text === '待评价'" class="orange">
              待评价
            </div>
            <div v-if="scope.row.status_text === '已取消'" class="red">
              已取消
            </div>
            <div v-if="scope.row.status_text === '退款中'" class="blue">
              退款中
            </div>
            <div v-if="scope.row.status_text === '已完成'" class="blue">
              已完成
            </div>
            <div v-if="scope.row.status_text === '配送中'" class="blue">
              配送中
            </div>
            <div v-if="scope.row.status_text === '已签收'" class="green">
              已签收
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="20%">
          <template slot-scope="scope">
            <div class="caozuo">
              <!-- <div
                v-if="scope.row.status_text === '待发货'"
                class="handleExamine hand_cs"
                @click="handleGo(scope.row)"
              >
                去发货
              </div> -->
              <div class="handleEdit hand_cs" @click="handleDetail(scope.row)">
                详情
              </div>
              <!--  -->
              <!-- <div
                v-if="scope.row.status_text === '待收货'"
                class="handleExamine1 hand_cs"
                @click="handleGoEdit(scope.row)"
              >
                修改物流信息
              </div> -->
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <Pagination :page="page" @onCurrentChange="handleCurrentChange" />
      </div>
      <el-dialog
        class="editDialog"
        title="详情"
        :visible.sync="dialogVisible"
        width="800px"
      >
        <Dialog v-if="dialogVisible" :type="2" :rowData="rowData"></Dialog>
      </el-dialog>
      <el-dialog
        title="详情"
        @close="close"
        :visible.sync="togoodsDialog"
        width="600px"
      >
        <div v-if="togoodsDialog" class="togoodsDialog">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="承运商" prop="shipping_com">
              <el-input
                v-model="ruleForm.shipping_com"
                placeholder="请输入承运商"
              ></el-input>
            </el-form-item>
            <el-form-item label="承运商单号" prop="shipping_code">
              <el-input
                v-model="ruleForm.shipping_code"
                placeholder="请输入承运商单号"
              ></el-input>
            </el-form-item>
            <el-form-item label="备注">
              <el-input
                v-model="ruleForm.remark"
                placeholder="请输入承运商单号"
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')"
                >提交</el-button
              >
            </el-form-item>
          </el-form>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import Dialog from "./order_detail.vue";
import Pagination from "@/components/Pagination.vue";
import { online_order_list, toSend } from "@/api/mall_management";
export default {
  components: { Pagination, Dialog },
  data() {
    return {
      loading: true,
      orderId: "",
      time: "",
      dialogVisible: false,
      page: {
        total: 0,
        pageNum: 1, // 当前页数
        pageSize: 10, // 每页的条数
      },
      title: "",
      deliverId: "",
      deliverName: "",
      deliverArr: [
        { id: "待支付", name: "待支付" },
        { id: "待发货", name: "待发货" },
        { id: "待收货", name: "待收货" },
        { id: "待评价", name: "待评价" },
        { id: "已取消", name: "已取消" },
        { id: "退款中", name: "退款中" },
        { id: "已完成", name: "已完成" },
      ],
      tableData: [],
      rowData: {}, //当前行数据 传给详情
      ruleForm: {
        shipping_com: "",
        shipping_code: "",
        remark: "",
      },
      rules: {
        shipping_com: [
          { required: true, message: "请输入承运商", trigger: "blur" },
        ],
        shipping_code: [
          { required: true, message: "请输入承运商单号", trigger: "blur" },
        ],
      },
      rowOid: "",
      togoodsDialog: false,
    };
  },
  methods: {
    //订单列表
    async online_order_list() {
      const { data, err } = await online_order_list({
        page: this.page.pageNum,
        oid: this.orderId,
        st_: this.time ? this.time[0] : 0,
        se_: this.time ? this.time[1] : 0,
        status: this.deliverId,
        type: 2,
      });
      if (err === 0) {
        this.loading = false;
        this.tableData = data.data;
        this.page.total = data.total;
        this.page.pageSize = data.per_page;
      }
    },
    async toSend() {
      const { msg, err } = await toSend({
        oid: this.rowOid,
        shipping_com: this.ruleForm.shipping_com,
        shipping_code: this.ruleForm.shipping_code,
        remark: this.ruleForm.remark,
      });
      if (err === 0) {
        this.$message({
          showClose: true,
          message: "操作成功",
          type: "success",
        });
        this.togoodsDialog = false;
        this.rowOid = "";
        this.ruleForm.shipping_com = "";
        this.ruleForm.shipping_code = "";
        this.ruleForm.remark = " ";
        this.online_order_list();
      } else {
        this.$message({
          showClose: true,
          message: msg,
          type: "error",
        });
      }
    },
    //去发货
    handleGo(row) {
      this.togoodsDialog = true;
      this.rowOid = row.oid;
    },
    //编辑物流信息
    handleGoEdit(row) {
      this.togoodsDialog = true;
      this.rowOid = row.oid;
      this.ruleForm.shipping_com = row.express.name;
      this.ruleForm.shipping_code = row.express.id;
      this.ruleForm.remark = row.express.remarks;
    },
    //关闭
    close() {
      this.rowOid = "";
      this.ruleForm.shipping_com = "";
      this.ruleForm.shipping_code = "";
      this.ruleForm.remark = " ";
    },
    //点击如发货提交
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.toSend();
        } else {
          return false;
        }
      });
    },
    //查询
    handleQuery() {
      this.loading = true;
      //调接口
      this.page.pageNum = 1;
      this.online_order_list();
    },
    //查看详情
    handleDetail(row) {
      this.dialogVisible = true;
      this.title = "编辑";
      this.rowData = row;
    },
    // 当前页: ${val}
    handleCurrentChange(val) {
      this.loading = true;
      this.page.pageNum = val;
      this.online_order_list();
    },
  },
  created() {
    this.online_order_list();
  },
};
</script>

<style lang="scss" scoped>
@import "@/style/index.scss";

.info {
  .title {
    font-size: 16px;
    margin-bottom: 13px;
  }
}
.pagination {
  display: flex;
  justify-content: flex-end;
  padding-top: 10px;
}
.el-select {
  width: 100%;
}

.tb {
  background-color: #fff;
  padding: 20px;
  box-sizing: border-box;
}
.row {
  display: flex;
  border-radius: 2px;
  border: 1px solid #ccc;
  width: 80px;
  .l {
    width: 80px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;

    i {
      margin-right: 6px;
      font-size: 18px;
    }
    &:hover {
      cursor: pointer;
    }
  }
  .l:nth-child(3) {
    border-right: 0;
  }
}
.editDialog {
  //   z-index: 2005 !important;
  /deep/.el-dialog {
    height: 75%;
    .el-dialog__body {
      height: 78%;
      overflow: auto;
    }
  }
}
.handleExamine {
  margin-right: 20px;
}
.togoodsDialog {
  padding: 0 40px 0 0;
  box-sizing: border-box;
}
</style>
